package cetc54.zhtx.client;

import cetc54.zhtx.start.ClientListenStatus;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

public class ClientHeartBeatInitializer extends ChannelInitializer<SocketChannel> {

    private HeartBeatClient heartBeatClient;

    private ClientListenStatus listenStatus;

    public ClientHeartBeatInitializer(HeartBeatClient heartBeatClient, ClientListenStatus listenStatus){
        this.heartBeatClient=heartBeatClient;
        this.listenStatus=listenStatus;
    }

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        //编解码器
        pipeline.addLast("stringEncoder",new StringEncoder());
        pipeline.addLast("stringDecoder",new StringDecoder());
        pipeline.addLast("pingHandler",new ClientPingHandler(heartBeatClient,listenStatus));
    }
}
